//
//  NewFoodDetailViewController.m
//  FoodFamily
//
//  Created by dlios on 15-6-20.
//  Copyright (c) 2015年 guoBang. All rights reserved.
//

#import "NewFoodDetailViewController.h"

@interface NewFoodDetailViewController ()

@end

@implementation NewFoodDetailViewController




- (void)viewDidLoad {
    [super viewDidLoad];

    self.view.backgroundColor = [UIColor greenColor];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"iconfont-fanhui.png"] style:UIBarButtonItemStylePlain target:self action:@selector(leftButton)];
    self.navigationItem.leftBarButtonItem.tintColor = [UIColor blackColor];
    
    self.tabBarController.tabBar.backgroundColor = [UIColor whiteColor];
    
        self.navigationItem.title =@"美食详情";
    
    self.picVC = [[PicViewController alloc]init];
    
    [self addChildViewController:self.picVC];
    [self.view addSubview:self.picVC.view];
    
    self.picVC.MyDelegate = self;
    
    
    
    UICollectionViewFlowLayout *Flowlayout = [[UICollectionViewFlowLayout alloc]init];
    Flowlayout.itemSize = CGSizeMake(WIDTH, HEIGHT - 120);
    
    Flowlayout.minimumInteritemSpacing = 0;
    Flowlayout.minimumLineSpacing = 0;
    Flowlayout.scrollDirection =UICollectionViewScrollDirectionHorizontal;
    Flowlayout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    
    
    
    
    self.collectionV = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0,WIDTH,HEIGHT-20-44-49)collectionViewLayout:Flowlayout];
    self.collectionV.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.collectionV];
    
    self.collectionV.pagingEnabled = YES;
    self.collectionV.bounces = NO;
    
    self.collectionV.delegate =self;
    self.collectionV.dataSource = self;
    
    
    [self.collectionV registerClass:[NewFoodDetailCollectionViewCell class] forCellWithReuseIdentifier:@"resure"];

 
    [self.collectionV  setContentOffset:CGPointMake(self.collectionV.frame.size.width * self.indexPath.row, 0) animated:NO];

    
    
}


-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{

    return self.array.count;

}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
   
    self.cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"resure"forIndexPath:indexPath];
    self.cell.backgroundColor = [UIColor whiteColor];
       FoodCityModle *foodCM = [self.array objectAtIndex:indexPath.row];
    self.cell.foodCM = foodCM;
    NSURL *url = [NSURL URLWithString:self.cell.foodCM.picture_url];
    
    [self.picVC.imageV sd_setImageWithURL:url];
    
    self.cell.myDelegate = self;
    
    
    self.cell.foodCM.num1 = indexPath.row;
    
   
    
    return self.cell;

}



-(void)leftButton{

    [self.navigationController popViewControllerAnimated:YES];
}
    


//双击按钮,通过协议实现的
-(void)bringButton{


    [self.view bringSubviewToFront:self.picVC.view];
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"iconfont-fanhui.png"] style:UIBarButtonItemStylePlain target:self action:nil];
    self.navigationItem.leftBarButtonItem.tintColor = [UIColor blackColor];
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor blackColor],NSFontAttributeName:[UIFont systemFontOfSize:19.0]}];

    [self makeTabBarHidden:YES];
   
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"C577E80E6E1E.png"] forBarMetrics:UIBarMetricsDefault];
    
      self.tabBarController.tabBar.barTintColor = [UIColor whiteColor];
    
}

//同过协议恢复原来的图片
-(void)bringButton1{

    [self makeTabBarHidden:NO];

    
    self.tabBarController.tabBar.barTintColor = [UIColor whiteColor];

 //恢复原来的颜色
//    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:123/255.0 green:169/255.0 blue:167/255.0 alpha:1.0];
     [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"690EFC73-E213-4C10-9FF7-CCE713AC7BC1.png"] forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor whiteColor],NSFontAttributeName:[UIFont systemFontOfSize:19.0]}];
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"iconfont-fanhui.png"] style:UIBarButtonItemStylePlain target:self action:@selector(leftButton)];
    self.navigationItem.leftBarButtonItem.tintColor = [UIColor blackColor];

    
    [self.view bringSubviewToFront:self.collectionV];

  
}

//隐藏tabBar

-(void)makeTabBarHidden:(BOOL)hide{


    if ([self.tabBarController.view.subviews count] < 2) {
        return;
    }
    UIView *contentView = [[UIView alloc]init];
    if ([[self.tabBarController.view.subviews objectAtIndex:0]isKindOfClass:[UITabBar class]]) {
        
        contentView = [self.tabBarController.view.subviews objectAtIndex:1];
    }else{
    
    
        contentView = [self.tabBarController.view.subviews objectAtIndex:0];
    
    }
    if (hide) {
        contentView.frame = self.tabBarController.view.bounds ;
        
        contentView.backgroundColor = [UIColor blackColor];
        
    }else{
        contentView.frame = CGRectMake(self.tabBarController.view.bounds.origin.x,self.tabBarController.view.bounds.origin.y,
        self.tabBarController.view.bounds.size.width,
  self.tabBarController.view.bounds.size.height - self.tabBarController.tabBar.frame.size.height);
    
     contentView.backgroundColor = [UIColor whiteColor];
    }

    self.tabBarController.tabBar.hidden = hide;

}

-(void)bringButton2:(NSInteger)num2{

    UserDetailViewController *userDVC = [[UserDetailViewController alloc]init];
    [self.navigationController pushViewController:userDVC animated:YES];
    [userDVC release];
    
    FoodCityModle *foodCM =[self.array objectAtIndex:num2];
    
    userDVC.user_id =foodCM.user_id;


}

-(void)dealloc{
    [_picVC release];
    [_mytime release];

    [_array release];
    [_collectionV release];
    [_cell release];
    [_foodCM release];
    [super dealloc];

}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


 
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
